//
//  ViewController.m
//  test
//
//  Created by kepuG on 16/9/26.
//  Copyright © 2016年 text. All rights reserved.
//

#import "ViewController.h"
//#import "Caculator.h"
//#import "CaculatorMaker.h"
#import "GQCaculator.h"
#import "GQCaculatorMaker.h"
#import "TestNetData.h"
#import "NextViewController.h"
#import "GQRedPakageView.h"

#define K_W [UIScreen mainScreen].bounds.size.width
#define K_H [UIScreen mainScreen].bounds.size.height


@interface ViewController ()


@property (strong ,nonatomic) UIWindow *kwindow;


@end

@implementation ViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    
//    [ProgressHUD show];
    
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
    btn.frame = CGRectMake(100, 100, 100, 50);
    btn.backgroundColor = [UIColor redColor];
    [btn addTarget:self action:@selector(btnAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
    
    [ProgressHUD show];
    
    id<UIApplicationDelegate> delegate =[[UIApplication sharedApplication] delegate ];
    
    if ([delegate respondsToSelector:@selector(window)]) {
        self.kwindow = [delegate performSelector:@selector(window)];
    }else{
        self.kwindow = [[UIApplication sharedApplication]keyWindow];
    }
    
   // [self dataDeal];
//    UIWindow * keyWindow = [[[UIApplication sharedApplication]delegate]window];
    
    UIView *kveiw = [[UIView alloc] initWithFrame:CGRectMake(0, 0,K_W, K_H)];
    
    kveiw.backgroundColor = [UIColor greenColor];
    
    [self.kwindow bringSubviewToFront:kveiw];
    
    [self.kwindow makeKeyAndVisible];
    
    [self.kwindow addSubview:kveiw];
    
    [self getext];
    
 //   [GQRedPakageView showPakege];
    
    // Do any additional setup after loading the view, typically from a nib.
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    [super touchesBegan:touches withEvent:event];
    [ProgressHUD dismiss];
}

-(void)getData{
    
    [TestNetData getDataUrl:@"/trip/triptype" success:^(id obj) {
        
        
    } fail:^(id obj) {
    
    }];
}
-(void)getext{ //
    
    [TestNetData getTextUrl:@"/organization/memberOrgVerify" succell:^(id obj) {
        //NSString *text = obj;
        NSLog(@"----text:%@",obj);
        
    } fail:^(id obj) {
        
    }];
}



-(void)btnAction{

    NextViewController *vc = [[NextViewController alloc] init];
    
//    vc.delegateSignal = [RACSubject subject];
//    
//    [vc.delegateSignal subscribeNext:^(id x) {
//        NSLog(@"=====%@",x);
//        
//    }];
//    
    
    
    [self presentViewController:vc animated:YES completion:nil];
}
//数据遍历
-(void)dataDeal{
    //数组遍历
    NSArray *number = @[@"1",@"2",@"3",@"4",@"5"];
//    [number.rac_sequence.signal subscribeNext:^(id x) {
//        NSLog(@"=====%@",x);
//    }];
//    NSLog(@"---------");
//    //遍历字典遍历出来的字典会被包装成RACTuple（元组对象）
//    NSDictionary *dicc = @{@"key1":@"value1",
//                          @"key2":@"value2",
//                          @"key3":@"value3"};
//    
//    
//    [dicc.rac_sequence.signal subscribeNext:^(RACTuple *x) {
//        
//        RACTupleUnpack(NSString *key,NSString *value) = x;
//同写法
//        NSString *nkey = x[0];
//        NSString *nvalue = x[1];
//        
//        NSLog(@"key:%@  value:%@",key,value);
//    }];
    
}




//链式编程
-(void)add{
    
    int i = [NSObject gqCaculatorMaker:^(GQCaculatorMaker *maker) {
        maker.add(3).add(5).add(10).add(30);
    }];
    NSLog(@"===i:%d",i);
}

//读本地文件
-(void)getLocalFile{

    //  NSData *data = [NSData dataWithContentsOfFile:filePath];
    //  NSData *jasonData = [NSJSONSerialization dataWithJSONObject:data options:NSJSONWritingPrettyPrinted error:nil];
    //    NSString *jsonStr = [[NSString alloc] initWithData:jasonData encoding:NSUTF8StringEncoding];
    //
    //  NSMutableDictionary *dic = [NSMutableDictionary alloc];
    NSString *filePath = @"/Users/chaopu/Desktop/pnr.txt";
    NSString *jsonstr = [[NSString alloc] initWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
    NSData *data = [jsonstr dataUsingEncoding:NSASCIIStringEncoding];
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
    NSLog(@"===file=%@",dic);
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
